<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\Url;
//use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model common\models\MktPost */
/* @var $form yii\widgets\ActiveForm */

$type = Html::getInputId($model,'post_type');
$JOB = \common\models\MktPost::POST_TYPE_JOB;

$js=<<<EOD
$("#$type").change( function()
{    
    $(".job, .cooperation").hide();
    var type = $("#$type").val();
    if (type == $JOB) {
        $(".job").show();
        $('#id_label_title').html('招聘职位');
        $('#id_label_content').html('岗位职责');        
    } else {
        $(".cooperation").show();
        $('#id_label_title').html('合作主题');
        $('#id_label_content').html('合作描述');        
    }

}).change();
EOD;
$this->registerJs($js, yii\web\View::POS_READY);

?>

<script type="text/javascript">
    $('#area_id').on('depdrop.change', function(event, id, value, count) {
    alert('aaaa');
    });

</script>

<div class="mkt-post-form">

    <?php $form = ActiveForm::begin(); ?>

	<?php echo $form->field($model, 'post_type')->dropDownList(common\models\MktPost::getPostTypeOption()) ?>

    <?php echo $form->field($model, 'user_id')->textInput(['maxlength' => true])->label('作者ID'); ?>

    <?php echo $form->field($model, 'title')->textInput(['maxlength' => true])->label('标题',['id'=>'id_label_title']); ?>

    <?php echo $form->field($model, 'content')->textarea(['rows' => 2])->label('详情',['id'=>'id_label_content']); ?>

    <?php //echo $form->field($model, 'industry_id')->textInput(['maxlength' => true]) ?>

    <?php //echo $form->field($model, 'area_id')->textInput(['maxlength' => true])->label('区域',['id'=>'id_label_area']); ?>


    <?php echo $form->field($model, 'parent_area_id')->dropDownList(\yii\helpers\ArrayHelper::map(
        \common\models\MktArea::find()->children()->all(),
        'id',
        'title'
    ), ['prompt'=>'选择区域...', 'id'=>'parent_area_id'])->label('区域'); ?>

    <?php //echo 'area_id='.$model->area_id; ?>

    <?php echo $form->field($model, 'area_id')->label('商圈')->widget(\kartik\depdrop\DepDrop::classname(), [
         'options' => ['id' => 'area_id'],
        // 'data'=>[2 => 'Tablets', 1=>'xxx'],
/*        
        'pluginEvents' => [
            "depdrop.init"=>"function() { alert('depdrop.init'); }"
        ],
*/        
         'pluginOptions'=>[
             'depends'=>['parent_area_id'],
             'initialize' => $model->isNewRecord ? false : true,
             'placeholder' => '选择商圈...',
             'url' => Url::to(['area/subcat'])
         ]
     ]); ?>

    <div class="cooperation">
    <?php echo $form->field($model, 'start_time')->textInput()->label('合作起始时间'); ?>

    <?php echo $form->field($model, 'end_time')->textInput()->label('合作结束时间'); ?>

    <?php //echo $form->field($model, 'cooperation_reward')->textarea(['rows' => 2]) ?>
	<?php echo $form->field($model, 'cooperation_reward')->dropDownList(common\models\MktPost::getPostCooperationRewardOption()) ?>

    </div>

    <div class="job">
	<?php echo $form->field($model, 'job_salary_min')->dropDownList(common\models\MktPost::getPostJobSalaryMinOption()) ?>

	<?php echo $form->field($model, 'job_salary_max')->dropDownList(common\models\MktPost::getPostJobSalaryMaxOption()) ?>

	<?php echo $form->field($model, 'job_education')->dropDownList(common\models\MktPost::getPostJobEducationOption()) ?>

	<?php echo $form->field($model, 'job_experience')->dropDownList(common\models\MktPost::getPostJobExperienceOption()) ?>

    <?php echo $form->field($model, 'job_age_min')->textInput([]) ?>

    <?php echo $form->field($model, 'job_age_max')->textInput([]) ?>
    </div>

	<?php echo $form->field($model, 'is_anoymous')->checkbox(common\wosotech\Util::getYesNoOptionName()) ?>

	<?php echo $form->field($model, 'status')->inline()->radioList(common\models\MktPost::getPostStatusOption())->label(false); ?>

    <div class="form-group">
        <?php echo Html::submitButton($model->isNewRecord ? '创建' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
